<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="ckeditor" uri="http://ckeditor.com" %>
<%@ taglib prefix="ckfinder" uri="http://ckfinder.com" %>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <!-- Title and other stuffs -->
  <title>美食信息管理</title> 
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="author" content="">
  <!-- Stylesheets -->
  <link href="${pageContext.request.contextPath}/style/bootstrap.css" rel="stylesheet">
  <!-- Font awesome icon -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/font-awesome.css"> 
  <!-- jQuery UI -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/jquery-ui.css"> 
  <!-- Calendar -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/fullcalendar.css">
  <!-- prettyPhoto -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/prettyPhoto.css">  
  <!-- Star rating -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/rateit.css">
  <!-- Date picker -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/bootstrap-datetimepicker.min.css">
  <!-- CLEditor -->
  <!-- Uniform -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/uniform.default.css"> 
  <!-- Bootstrap toggle -->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/style/bootstrap-switch.css">
  <!-- Main stylesheet -->
  <link href="${pageContext.request.contextPath}/style/style.css" rel="stylesheet">
  <!-- Widgets stylesheet -->
  <link href="${pageContext.request.contextPath}/style/widgets.css" rel="stylesheet">   
  
  <script type="text/javascript"  src="${pageContext.request.contextPath}/ckeditor/ckeditor.js"></script>  
  <script type="text/javascript"  src="${pageContext.request.contextPath}/ckfinder/ckfinder.js"></script>  
  <!-- Favicon -->
  <link rel="shortcut icon" href="img/favicon/favicon.png">
  <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.js"></script>
  <script type="text/javascript" src="${pageContext.request.contextPath}/layer/layer.js"></script>

</head>

<body>

<%@ include file="../jsp/header.jsp" %>
<!-- Main content starts -->

<div class="content">

<%@ include file="../jsp/adminSidebar.jsp" %>

  	  <!-- Main bar -->
  	<div class="mainbar">
      
	    <!-- Page heading -->
	    <div class="page-head">
	      <h2 class="pull-left"><i class="icon-home"></i>美食信息管理</h2>

        <!-- Breadcrumb -->
        <div class="bread-crumb pull-right">
          <a href="${pageContext.request.contextPath}/adminMain.action"><i class="icon-home"></i> 首页</a> 
          <!-- Divider -->
          <span class="divider">/</span> 
          <a href="#" class="bread-current">控制台</a>
        </div>
        <div class="clearfix"></div>
	    </div>
	    <!-- Page heading ends -->
	    <!-- Matter -->
	    <div class="matter">
        <div class="container">
          <div class="row">
			<!-- Form starts.  -->
              <div class="form-horizontal" role="form"  id="frmDelicious">
              <input type="hidden" id="hidOperateType" name="hidOperateType" value=""/><!-- 带参数，传参数（隐藏的） -->
              <input type="hidden" id="hidDeliciousId" name="hidDeliciousId"/><!-- 带参数，传参数（隐藏的） -->
              <input type="hidden" id="hidPicture" name="hidPicture"/><!-- 带参数，传参数（隐藏的） -->
              <input type="hidden" id="hidCurrentPageIndex" name="hidCurrentPageIndex" 
                value="${currentPageIndex}"/>
              <input type="hidden" id="hidPageSize" name="hidPageSize" value="${pageSize}"/>
              <input type="hidden" id="hidSortField" name="hidSortField" value="${sortField }"/>	
           	  <input type="hidden" id="hidSortString" name="hidSortString" value="${sortString }"/>
                  
            <div class="col-md-12">

              <div class="widget wgreen">
               
                <div class="widget-head">
                  <div class="pull-left">美食信息填写</div>
                  <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-down"></i></a> 
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                  </div>
                  <div class="clearfix"></div>
                </div>

                <div class="widget-content" style="display:none" id="modify">
                  <div class="padd">
                   <form action="${pageContext.request.contextPath}/addDelicious.action" method="post" enctype="multipart/form-data">
                    <div class="form-group">
                      <label class="col-lg-4 control-label">美食名称</label>
                      <div class="col-lg-8">
                        <input type="text" class="form-control" id="txtDeliciousName" name="txtDeliciousName" 
                        placeholder="美食名称" value="">
                        <span class="label label-danger" id="spanDeliciousName"></span>
                      </div>
                    </div>
                    <div class="form-group" id="image1">
                      <label class="col-lg-4 control-label" >美食图片</label>
                      <div class="col-lg-8">
                        <input type="file" class="form-control" id="txtDeliciousPicture" name="txtDeliciousPicture" placeholder="美食图片" >
                      </div>
                    </div>
                    <div class="form-group" hidden="hidden" id="image2">
                      <label class="col-lg-4 control-label" >美食图片</label>
                      <div class="col-lg-8">
                      	<img alt="美食图片" src="" id="image" style="max-height:50px; max-width:80px;">
                      	<!-- <input type="file" class="form-control" id="txtDeliciousPicture1" name="txtDeliciousPicture1" placeholder="美食图片" > -->
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-lg-4 control-label">美食评分</label>
                      <div class="col-lg-8">
                        <input type="text" class="form-control" id="txtDeliciousScore" name="txtDeliciousScore" 
                        placeholder="美食评分（0-10）" >
                        <span class="label label-danger" id="spanDeliciousScore"></span>
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-lg-4 control-label">美食故事</label>
                      <div class="col-lg-8">
                        <input type="text" class="form-control" id="txtRemark" name="txtRemark" 
                        placeholder="美食故事" >
                        <span class="label label-danger" id="spanRemark"></span>
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-lg-4 control-label"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">选择频道</font></font></label>
                      <div class="col-lg-8">
                        <select class="form-control" id="txtChannelId" name="txtChannelId" >
						</select>
                      </div>
                    </div>  
                    <div class="form-group">
                      <label class="col-lg-4 control-label">美食做法</label>
                      <div class="col-lg-8">
                        <textarea class="form-control" rows="3" id="txtDeliciousPractice" name="txtDeliciousPractice" 
                          placeholder="美食做法">
						</textarea>
                        <ckeditor:replace replace="txtDeliciousPractice" basePath="/Mydelicious/ckeditor/" />
                        <ckfinder:setupCKEditor  basePath="/Mydelicious/ckeditor/"/>
                      </div>
                    </div>    
                    <hr />
                    <div class="form-group">
                      <div class="col-lg-offset-1 col-lg-9">
                      <div id ="Modify1" >
                        <button type="submit" class="btn btn-primary">添加</button>                             
                        <button type="reset" class="btn btn-default">取消</button>
                      </div>
                       </div>
                   </div>
                   </form>
                   <div class="form-group">
                      <div class="col-lg-offset-1 col-lg-9">
                     	<div id="Modify2" style="display:none" >
	                        <button onclick="saveDelicious()" class="btn btn-primary">保存</button>                             
	                        <button class="btn btn-default" onclick="cancelSaveDelicious()" >取消</button>
                        </div>
                       </div>
                   </div>
	             </div>
	           </div>
	             <div class="widget-foot">
	               <!-- Footer goes here -->
	             </div>
	         </div>  
			<div class="widget wgreen">
                <div class="widget-head">
                  <div class="pull-left">查询美食信息</div>
                  <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-down"></i></a> 
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                  </div>
                  <div class="clearfix"></div>
                </div>

                <div class="widget-content" style="display:none" id="search">
                  <div class="padd">
                    <div class="form-group">
                      <label class="col-lg-4 control-label">美食名称</label>
                      <div class="col-lg-8">
                        <input type="text" class="form-control" id="txtSearchDeliciousName" name="txtSearchDeliciousName" 
                        placeholder="美食名称"
                        value="${searcher.deliciousName}"
                         >
                        <span class="label label-danger" id="spanSearch"></span>
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-lg-4 control-label">选择频道</label>
                      <div class="col-lg-8">
                        <select class="form-control"  id="txtSearchChannelId" name="txtSearchChannelId" >
						</select>
                      </div>
                    </div>  
                    <div class="form-group">
                      <div class="col-lg-offset-1 col-lg-9">
                        <button class="btn btn-primary" onclick="searchDelicious()">查询</button>                             
                        <button type="reset" class="btn btn-default" onclick="cancelSearchDelicious()">取消查询</button>
                       </div>
                   </div>
	             </div>
	           </div>
	             <div class="widget-foot">
	               <!-- Footer goes here -->
	             </div>
	         </div>
	       </div>
		</div>
	   </div>


       <!-- Table -->
         <div class="row">
           <div class="col-md-12">
             <div class="widget">
             <div class="widget-head">
               <div class="pull-left">美食信息表</div>
               <div class="widget-icons pull-right">
                 <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a> 
                 <a href="#" class="wclose"><i class="icon-remove"></i></a>
               </div>
              
               <div class="clearfix"></div>
             </div>

               <div class="widget-content">
				<script type="text/javascript">
				    $(function () {
				        $("div").on("mouseenter",function() {
				            if (this.offsetWidth < this.scrollWidth) {
				                var that = this;
				                var text = $(this).text();
				                layer.tips(text, that,{
				                    tips: 1,
				                    time: 2000
				                });
				            }
				        });
				    })
				</script>
                 <table class="table table-striped table-bordered table-hover">
                   <thead>
                     <tr>
                       <th><a href="javascript: sorting('deliciousId')" >序号</a></th>	<%--排序字段 --%>
                       <th><a href="javascript: sorting('deliciousTime')">创建时间</a></th>
                       <th><a href="javascript: sorting('deliciousName')">美食名称</a></th>
                       <th><a href="javascript: sorting('deliciousPicture')">美食图片</a></th>
                       <th><a href="javascript: sorting('deliciousScore')">美食评分</a></th>
                       <th><a href="javascript: sorting('userId')">所属用户</a></th>
                       <th><a href="javascript: sorting('channelId')">所属频道</a></th>
                       <th>操作</th>                          
                     </tr>
                   </thead>
                   <tbody id="myTable">
                     <c:forEach items="${itemList}" var="delicious" >
                     <%-- begin="${(currentPageIndex - 1) * pageSize }" end="${currentPageIndex * pageSize - 1 }"> --%>
                     <tr>
                       <td>${delicious.deliciousId} </td>
                       <td title="<fmt:formatDate value="${delicious.deliciousTime}" pattern="yyyy.MM.dd HH:mm:ss"/>">
                       <fmt:formatDate value="${delicious.deliciousTime}" pattern="yyyy.MM.dd HH:mm:ss"/>
                       </td>
                       <td><a href="${pageContext.request.contextPath}/showDeliciousPractice.action?deliciousId=${delicious.deliciousId}">${delicious.deliciousName}</a></td>
                       <td  onclick="deliciousPicture('${delicious.deliciousPicture}')" >
						<img src="/pic/${delicious.deliciousPicture}" style="max-height:50px; max-width:80px;"/>
					   </td>
                       <td>${delicious.deliciousScore}</td>
                       <td>${delicious.userName}</td>
                       <td>${delicious.channelName}</td>
                       <td>
                           <button class="btn btn-xs btn-warning" onclick="modifyDelicious(${delicious.deliciousId})" ><i class="icon-pencil"></i> </button>
                           <button class="btn btn-xs btn-danger" onclick="removeDelicious(${delicious.deliciousId})"><i class="icon-remove"></i> </button>                          
                       </td>
                     </tr>    
                     
                     </c:forEach>                       
                                        
                   </tbody>
                   <tbody id="tbody-result"></tbody>
                 </table>

                 <div class="widget-foot">  
                    共${rowCount}条数据&nbsp;&nbsp;&nbsp;第${currentPageIndex}/${pageCount}页 &nbsp;&nbsp;&nbsp;
		               <label>
		                 <input type="radio" name="radPageSize"  value="20" onclick="resize(this.value)" <c:if test="${pageSize == 20}">checked</c:if>>20条/页
		               </label>&nbsp;&nbsp;
		               <label>
		                 <input type="radio" name="radPageSize" value="30" onclick="resize(this.value)" <c:if test="${pageSize == 30}">checked</c:if>>30条/页
		               </label>&nbsp;&nbsp;
		               <label>
		                 <input type="radio" name="radPageSize" value="50" onclick="resize(this.value)" <c:if test="${pageSize == 50}">checked</c:if>>50条/页
		               </label>
                     <ul class="pagination pull-right">
                     
                     <c:if test="${currentPageIndex <= 1 }">
                          <li><a href="#">首页</a></li>
                          <li><a href="#">上一页</a></li>
                        </c:if>
                        <c:if test="${currentPageIndex > 1 }">
                          <li><a href="javascript: paging(1)">首页</a></li>
                          <li><a href="javascript: paging(${currentPageIndex - 1 })">上一页</a></li>
                        </c:if>
                        <c:if test="${currentPageIndex >= pageCount }">
                          <li><a>下一页</a></li>
                          <li><a>尾页</a></li>
                        </c:if>  
                        <c:if test="${currentPageIndex < pageCount }">
                          <li><a href="javascript: paging(${currentPageIndex + 1 })">下一页</a></li>
                          <li><a href="javascript: paging(${pageCount })">尾页</a></li>
                        </c:if>
                          <li><a target="_blank" href="${pageContext.request.contextPath}/admin/ExportAllDelicioussServlet">导出全部</a></li>  
                     </ul>                    
                   <div class="clearfix"></div> 
                 </div>
               </div>
             </div>
           </div>
         </div>
 
		<!-- Matter ends -->

    </div>
 </div>
 </div>

   <!-- Mainbar ends -->
   <div class="clearfix"></div>

</div>
<!-- Content ends -->

<%@include file="../jsp/admin_footer.jsp" %>


<!-- Scroll to top -->
<span class="totop"><a href="#"><i class="icon-chevron-up"></i></a></span> 

<!-- JS -->
<script src="${pageContext.request.contextPath}/js/jquery.js"></script> <!-- jQuery -->
<script src="${pageContext.request.contextPath}/js/bootstrap.js"></script> <!-- Bootstrap -->
<script src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.min.js"></script> <!-- jQuery UI -->
<script src="${pageContext.request.contextPath}/js/fullcalendar.min.js"></script> <!-- Full Google Calendar - Calendar -->
<script src="${pageContext.request.contextPath}/js/jquery.rateit.min.js"></script> <!-- RateIt - Star rating -->
<script src="${pageContext.request.contextPath}/js/jquery.prettyPhoto.js"></script> <!-- prettyPhoto -->

<!-- jQuery Flot -->
<script src="${pageContext.request.contextPath}/js/excanvas.min.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.flot.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.flot.resize.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.flot.pie.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery.flot.stack.js"></script>

<!-- jQuery Notification - Noty -->
<script src="${pageContext.request.contextPath}/js/jquery.noty.js"></script> <!-- jQuery Notify -->
<script src="${pageContext.request.contextPath}/js/themes/default.js"></script> <!-- jQuery Notify -->
<script src="${pageContext.request.contextPath}/js/layouts/bottom.js"></script> <!-- jQuery Notify -->
<script src="${pageContext.request.contextPath}/js/layouts/topRight.js"></script> <!-- jQuery Notify -->
<script src="${pageContext.request.contextPath}/js/layouts/top.js"></script> <!-- jQuery Notify -->
<!-- jQuery Notification ends -->

<script src="${pageContext.request.contextPath}/js/sparklines.js"></script> <!-- Sparklines -->
<script src="${pageContext.request.contextPath}/js/jquery.cleditor.min.js"></script> <!-- CLEditor -->
<script src="${pageContext.request.contextPath}/js/bootstrap-datetimepicker.min.js"></script> <!-- Date picker -->
<script src="${pageContext.request.contextPath}/js/jquery.uniform.min.js"></script> <!-- jQuery Uniform -->
<script src="${pageContext.request.contextPath}/js/bootstrap-switch.min.js"></script> <!-- Bootstrap Toggle -->
<script src="${pageContext.request.contextPath}/js/filter.js"></script> <!-- Filter for support page -->
<script src="${pageContext.request.contextPath}/js/custom.js"></script> <!-- Custom codes -->
<script src="${pageContext.request.contextPath}/js/charts.js"></script> <!-- Charts & Graphs -->

<!-- Script for this page -->
<script type="text/javascript">
$(function () {
	getService();
    /* Bar Chart starts */

    var d1 = [];
    for (var i = 0; i <= 20; i += 1)
        d1.push([i, parseInt(Math.random() * 30)]);

    var d2 = [];
    for (var i = 0; i <= 20; i += 1)
        d2.push([i, parseInt(Math.random() * 30)]);


    var stack = 0, bars = true, lines = false, steps = false;
    
    function plotWithOptions() {
        $.plot($("#bar-chart"), [ d1, d2 ], {
            series: {
                stack: stack,
                lines: { show: lines, fill: true, steps: steps },
                bars: { show: bars, barWidth: 0.8 }
            },
            grid: {
                borderWidth: 0, hoverable: true, color: "#777"
            },
            colors: ["#ff6c24", "#ff2424"],
            bars: {
                  show: true,
                  lineWidth: 0,
                  fill: true,
                  fillColor: { colors: [ { opacity: 0.9 }, { opacity: 0.8 } ] }
            }
        });
    }
    //plotWithOptions();
    
    $(".stackControls input").click(function (e) {
        e.preventDefault();
        stack = $(this).val() == "With stacking" ? true : null;
        plotWithOptions();
    });
    $(".graphControls input").click(function (e) {
        e.preventDefault();
        bars = $(this).val().indexOf("Bars") != -1;
        lines = $(this).val().indexOf("Lines") != -1;
        steps = $(this).val().indexOf("steps") != -1;
        plotWithOptions();
    });

    /* Bar chart ends */

});


/* Curve chart starts */

$(function () {

	//jq 选中resize中值为pageSize的选项
	$("#resize option[value='${pageSize}']").attr('selected', true);
	
    var sin = [], cos = [];
    for (var i = 0; i < 14; i += 0.5) {
        sin.push([i, Math.sin(i)]);
        cos.push([i, Math.cos(i)]);
    }

    var plot = $.plot($("#curve-chart"),
           [ { data: sin, label: "sin(x)"}, { data: cos, label: "cos(x)" } ], {
               series: {
                   lines: { show: true, fill: true},
                   points: { show: true }
               },
               grid: { hoverable: true, clickable: true, borderWidth:0 },
               yaxis: { min: -1.2, max: 1.2 },
               colors: ["#1eafed", "#1eafed"]
             });

    function showTooltip(x, y, contents) {
        $('<div id="tooltip">' + contents + '</div>').css( {
            position: 'absolute',
            display: 'none',
            top: y + 5,
            left: x + 5,
            border: '1px solid #000',
            padding: '2px 8px',
            color: '#ccc',
            'background-color': '#000',
            opacity: 0.9
        }).appendTo("body").fadeIn(200);
    }

    var previousPoint = null;
    $("#curve-chart").bind("plothover", function (event, pos, item) {
        $("#x").text(pos.x.toFixed(2));
        $("#y").text(pos.y.toFixed(2));

        if ($("#enableTooltip:checked").length > 0) {
            if (item) {
                if (previousPoint != item.dataIndex) {
                    previousPoint = item.dataIndex;
                    
                    $("#tooltip").remove();
                    var x = item.datapoint[0].toFixed(2),
                        y = item.datapoint[1].toFixed(2);
                    
                    showTooltip(item.pageX, item.pageY, 
                                item.series.label + " of " + x + " = " + y);
                }
            }
            else {
                $("#tooltip").remove();
                previousPoint = null;            
            }
        }
    }); 

    $("#curve-chart").bind("plotclick", function (event, pos, item) {
        if (item) {
            $("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
            plot.highlight(item.series, item.datapoint);
        }
    });

});


function checkInput(){
	var txtDeliciousName = document.getElementById("txtDeliciousName");
	var spanDeliciousName = document.getElementById("spanDeliciousName");
	
	if(txtDeliciousName.value.length == 0){
		spanDeliciousName.innerHTML = "美食名称不能为空。";
		return false;
	}
	else{
		spanDeliciousName.innerHTML="";
		return true;
	}
}
function checkSearch(){
	var txtSearchDeliciousName = document.getElementById("txtSearchDeliciousName");
	var txtSearchAddress = document.getElementById("txtSearchAddress");
	var txtSearchDescription = document.getElementById("txtSearchDescription");
	var spanSearch = document.getElementById("spanSearch");
	
	if(txtSearchDeliciousName.value.length == 0
		&&txtSearchAddress.value.length == 0
		&&txtSearchDescription.value.length == 0) {
		spanSearch.innerHTML = "美食名称不能为空。";
		return false;
	}
	else{
		spanSearch.innerHTML="";
		return true;
	}
}
function addDelicious(){
 if(checkInput()) {
	var hidOperateType = document.getElementById("hidOperateType");//获取表单
	var frmDelicious = document.getElementById("frmDelicious");
	
	hidOperateType.value="add";
	frmDelicious.submit();	
	}
}

function removeDelicious(deliciousId){
	var user_json = {  
            "deliciousId":deliciousId
            }      
	//js对象转换成JSON字符串  
    var jason_str = JSON.stringify(user_json);  
	if(confirm("确定要删除么？")){
		//Ajax发送数据给后台  
        $.ajax({  
            url :"${pageContext.request.contextPath }/deleteDelicious.action",   
            cache : true,  
            type : "post",  
            datatype : "json",  
            contentType : "application/json; charset=utf-8",  
            data : jason_str,  
            success : function (data){  
             	//返回空值  
                if(data == 0){  
                    alert("删除出现未知错误！");  
                } else{  //存在该用户  
                	alert("删除成功！");
                    }
                window.location.reload();
                }
        	
        });  
	}
}

function modifyDelicious(deliciousId){
	var user_json = {  
            "deliciousId":deliciousId
            }   
	
	//js对象转换成JSON字符串  
    var jason_str = JSON.stringify(user_json);  
	//Ajax发送数据给后台  
    $.ajax({  
        url :"${pageContext.request.contextPath }/updateDelicious.action",   
        cache : true,  
        type : "post",  
        datatype : "json",  
        contentType : "application/json; charset=utf-8",  
        data : jason_str,  
        success : function (data){  
         	//返回空值  
         	if(data.length > 0){
         		var editor = CKEDITOR.instances["txtDeliciousPractice"]; //你的编辑器的"name"属性的值
         	    if (editor) { 
         	            editor.destroy(true);//销毁编辑器
         	    }       
         	    
         		$("#modify").css('display','block'); 
         		$("#Modify1").css('display','none');
         		$("#Modify2").css('display','block');
         		
         		$("#image2").show();
         		$("#image1").hide();
         		
         		$("#hidDeliciousId").val("");
         		$("#txtDeliciousName").val("");
         		$("#txtDeliciousScore").val("");
         		
         		var src = "/pic/" + data[0].deliciousPicture;
         		$("#hidPicture").val(data[0].deliciousPicture);
         		$("#image").attr("src",src);
         		
         		$("#hidDeliciousId").val(data[0].deliciousId);
         		$("#txtDeliciousName").val(data[0].deliciousName);
         		$("#txtDeliciousScore").val(data[0].deliciousScore);
         		$("#txtChannelId").val(data[0].channelId);
         		$("#txtDeliciousPractice").val(data[0].deliciousPractice);//对editor赋值
         		
         		CKEDITOR.replace(txtDeliciousPractice); //替换编辑器，editorID为ckeditor的"id"属性的值
         	}
         }
    });  
}

function cancelSaveDelicious(){
	$("#modify").css('display','none'); 
	$("#Modify1").css('display','block');
	$("#Modify2").css('display','none');
	$("#hidDeliciousId").val("");
	$("#txtDeliciousName").val("");
	$("#image").attr("src","");
	$("#txtDeliciousPicture").val("");
	//$("#txtDeliciousPractice").val("");
	$("#txtDeliciousScore").val("");
	$("#hidPicture").val("");
	$("#image1").show();
	$("#image2").hide();
	window.location.reload();
}

function saveDelicious() {
	var deliciousId = $("#hidDeliciousId").val();
	var deliciousName = $("#txtDeliciousName").val();
	//var src = $("#image").attr("src");
	var src = $("#hidPicture").val();
	var deliciousPicture = $("#txtDeliciousPicture1").val(); 
	if(deliciousPicture == null || deliciousPicture == ""){
		deliciousPicture = src;	
	}
	var deliciousScore = $("#txtDeliciousScore").val();
	var channelId = $("#txtChannelId").val();
	var deliciousPractice = CKEDITOR.instances['txtDeliciousPractice'].getData();
	//var deliciousPractice = $("#txtDeliciousPractice").val();
	var user_json = {
		   "deliciousId":deliciousId,
           "deliciousName":deliciousName,
           "deliciousScore":deliciousScore,
           "channelId":channelId,
           /* "deliciousPicture":deliciousPicture, */
           "deliciousPractice":deliciousPractice
           }      
	//js对象转换成JSON字符串  
    var jason_str = JSON.stringify(user_json);
		if(checkInput()) {
		    $.ajax({  
		        url :"${pageContext.request.contextPath }/saveDelicious.action",   
		        cache : true,  
		        type : "post",  
		        datatype : "json",  
		        contentType : "application/json; charset=utf-8",  
		        data : jason_str,  
		        success : function(data){  
		            //返回空值  
		            if(data == 0){  
		                alert("修改出现未知错误！");  
		                //window.location.href = "sighIn.html";  
		            } else{ 
		            	alert("修改成功！");
		            	/* $("#image1").show();
		            	$("#image2").hidden(); */
		                }  
		            window.location.reload();
		            }  
		    });
		}
}

function paging(pageIndex) {
	var frmDelicious = document.getElementById("frmDelicious");
	var hidOperateType = document.getElementById("hidOperateType");
	var hidCurrentPageIndex = document.getElementById("hidCurrentPageIndex");
	
	hidCurrentPageIndex.value = pageIndex;
	hidOperateType.value = "paging";
    frmDelicious.submit();
}

function sorting(sortField){
	var frmDelicious = document.getElementById("frmDelicious");
	var hidOperateType = document.getElementById("hidOperateType");//获取表单
	var hidSortField = document.getElementById("hidSortField");

	hidSortField.value = sortField;
	hidOperateType.value="sorting";
	frmDelicious.submit();
}

function resize(pageSize) {
	var frmDelicious = document.getElementById("frmDelicious");
	var hidOperateType = document.getElementById("hidOperateType");
	var hidPageSize = document.getElementById("hidPageSize");
	
	hidPageSize.value = pageSize;
	hidOperateType.value = "resize";
    frmDelicious.submit();
}
function getLocalTime(nS) {     
	   return new Date(parseInt(nS)).toLocaleString().replace(/:\d{1,2}$/,' ');     
	}
function searchDelicious() {
	if (checkSearch()) {
		var deliciousName = $("#txtSearchDeliciousName").val();
		$("#myTable").hide();
		var str = null;
		var user_json = {  
		           "deliciousName":deliciousName,
		           }      
		//js对象转换成JSON字符串  
		var jason_str = JSON.stringify(user_json);
	    $.ajax({  
	        url :"${pageContext.request.contextPath }/searchDelicious.action",   
	        cache : true,  
	        type : "post",  
	        datatype : "json",  
	        contentType : "application/json; charset=utf-8",  
	        data : jason_str,  
	        success : function(data){ 
	        if(data.length>0){
	        	   for (i in data) { 
	        		  str += "<tr>" +
	        		  "<td>" + data[i].deliciousId + "</td>" +
	        		  "<td> " +  getLocalTime(data[i].deliciousTime) + 
	        		  "</td>" +
	        		  "<td>" + data[i].deliciousName + "</td>" ;
	        		  str+="<td  onclick='deliciousPicture('" +data[i].deliciousPicture+
	        		  "')' >" + " <img src='/pic/" +
	        		  data[i].deliciousPicture + 
	        		  " ' style='max-height:50px; max-width:80px;'/> "+ " </td>";
	                  str += "<td>" + data[i].deliciousScore + "</td>" +
	                  "<td>" + data[i].userId + "</td>" +
	                  "<td>" + data[i].channelId + "</td>" +
	                  "<td>" +
	                  "<button class='btn btn-xs btn-warning' onclick='modifyDelicious( " +
	                    		  data[i].deliciousId +
	                    		  " )' > " +
	                      "<i class='icon-pencil'></i> </button>" +
	                      "<button class='btn btn-xs btn-danger' onclick='removeDelicious( " +
	                    		  data[i].deliciousId +
	                    		  " )'> " +
	                      "<i class='icon-remove'></i> </button> " +
	                 "</td>" +
	                "</tr>" ;    
	        	   }
    	        	  $("#tbody-result").prepend(str);
    	           }
	    		}
	   		});
	    }
}

function cancelSearchDelicious() {
	$("#myTable").show();
	$("#tbody-result").hide();
	$("#search").css('display','none');
	$("#txtSearchDeliciousName").val("");
}

function deliciousPicture(data){
	var data = "/pic/"+data;
	layer.open({
	      type: 1,
	      shadeClose: true, //点击遮罩关闭
	      content: '<img id="deliciousPicture" src=" ' + data +'" style="width: 100%;height: 100%; objec-fit: cover;"/>'
	    });
}
function getService() {
	var str = null;
	$("select[name=txtChannelId]").empty();      //清空  
	$("select[name=txtSearchChannelId]").empty();      //清空  
	//Ajax发送数据给后台  
    $.ajax({  
        url :"${pageContext.request.contextPath }/allChannel.action",   
        cache : true,  
        type : "post",  
        datatype : "json",  
        contentType : "application/json; charset=utf-8",  
        data : "",  
        success : function (data){  
         	 for (var i in data) { 
       		     str += "<option value='"+ data[i].channelId + "'>" +data[i].channelName+"</option>";
	       	  } 
	       	  $("#txtChannelId").prepend(str);
	       	  $("#txtSearchChannelId").prepend(str);
	         },  
	         error: function (msg) {  
	             alert("出错了！");  
	         }  
    });  
}

</script>

</body>
</html>